import Vue from 'vue'
import Vuex from 'Vuex'
import utils from '../utils'
Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    signature: '', // 签名
    partnername: '', // 添加宣传语图片的动态名称
    nonceString: '',
    uploadimg: '', // 绑卡上传的图片
    // content_id: '', // 收藏时保存文章id
    show: false,
    mobile: '', // 忘记密码传送手机号
    NowCode: '',
    NowMobile: '',
    noncestr: '', // 随机串
    Code: '', // 授权code值
    wxCode: '', // 微信授权码
    userID: localStorage.getItem('userid') || '',
    userkey: localStorage.getItem('userkey') || '',
    usermobile: '', // 用户表单手机号
    uservcode: '', // 用户表单 手机验证码,
    userpartnerId: '', // 用户表单 合作方ID
    shareChannel: '', // 用户表单 申请渠道
    userapplyID: '', // 用户表单 userId
    userpostId: '', // 用户表单 文章id
    userpicId: '', // 用户表单 图片id
    pictureStore: localStorage.getItem('picture') || '', // 图文推广参数
    articlepartnerId: '', // 文章推广合作方id
    Url: process.env.BASE_URL,
    shareTitle: '贷款让你快速拿到钱', // 默认分享标题
    shareDesc: '悠闲贷，海量借款平台任意选，简单、快速、安全！', // 默认分享描述
    shareLink: '',
    shareImg: process.env.BASE_URL + '/static/img/uxd_logo.png', // 分享默认图片
    imgvcode: process.env.BASE_URL + '/bee-api/captcha/captcha?captchaId=', // 图形验证码
    credit_type: '',
    typeTab: '', // 贷款，信用卡切换
    logoUrl: '../../static/img/partnerId_img/' // 二维码中间logo地址
  },
  mutations: {
    changeIndexConf: (state, data) => {
      Object.assign(store.getters.getIndexinfo, data) // 使用getters获取处理后的数据源然后进行浅拷贝
    },
    resetShare: (state, data) => { // 重设分享默认数据
      state.shareTitle = '贷款让你快速拿到钱'
      state.shareDesc = '悠闲贷，海量借款平台任意选，简单、快速、安全！'
      state.shareImg = process.env.BASE_URL + '/static/img/uxd_logo.png'
      state.shareLink = ''
      state.typeTab = data
    },
    creditShare: (state, data) => {
      state.typeTab = data
      state.shareLink = ''
      state.shareImg = process.env.BASE_URL + '/static/img/uxd_logo.png'
      state.shareTitle = '送你一张信用卡，赶快来申请吧！'
      state.shareDesc = '悠闲贷，信用卡快速申请通道，产品多，额度高，门槛低，发卡快！'
    }
  },
  actions: {
    changefund (context) {
      context.commit('changeNUm')
    }
  },
  getters: {
    getIndexinfo: state => {
      return Object.assign(state)
    },
    shareLink: state => {
      if (state.shareLink === '') {
        console.log(state.typeTab, state.shareTitle)
        if (state.typeTab === '1') {
          return process.env.BASE_URL +
          '/creditLogin/index' +
          '?shareParam=share&userId=' +
          (utils.getQueryString('userId') || localStorage.getItem('userid')) + '&typeTab=' + state.typeTab
        } else {
          return process.env.BASE_URL +
          '/creditLogin/index' +
          '?shareParam=share&userId=' +
          (utils.getQueryString('userId') || localStorage.getItem('userid'))
        }
      } else {
        return state.shareLink
      }
    }
  }
})
export default store
